package rad.framework.uml2.uml.edit.providers.elementItemProvider.namedElement.vertex;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.uml2.uml.Pseudostate;
import org.eclipse.uml2.uml.PseudostateKind;
import org.eclipse.uml2.uml.UMLPackage;

import rad.framework.uml2.uml.edit.UMLEditPlugin;

public class PseudostateItemProvider
		extends VertexItemProvider
		implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {

	public PseudostateItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public List getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			addKindPropertyDescriptor(object);
			addStateMachinePropertyDescriptor(object);
			addStatePropertyDescriptor(object);
		}
		return itemPropertyDescriptors;
	}

	protected void addKindPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_Pseudostate_kind_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_Pseudostate_kind_feature", "_UI_Pseudostate_type"),
				UMLPackage.Literals.PSEUDOSTATE__KIND, true, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
	}

	protected void addStateMachinePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_Pseudostate_stateMachine_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_Pseudostate_stateMachine_feature", "_UI_Pseudostate_type"),
				UMLPackage.Literals.PSEUDOSTATE__STATE_MACHINE, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	protected void addStatePropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_Pseudostate_state_feature"),
				getString("_UI_PropertyDescriptor_description", "_UI_Pseudostate_state_feature", "_UI_Pseudostate_type"),
				UMLPackage.Literals.PSEUDOSTATE__STATE, true, null, null, new String[] { "org.eclipse.ui.views.properties.expert"
				}));
	}

	@Override
	public Object getImage(Object object) {
		if (((Pseudostate) object).getKind().equals(PseudostateKind.CHOICE_LITERAL)) {
			return overlayImage(object, getResourceLocator().getImage("full/obj16/Pseudostate_choice"));
		} else {
			return overlayImage(object, getResourceLocator().getImage("full/obj16/Pseudostate"));
		}
	}

	@Override
	public String getText(Object object) {
		return appendLabel(appendType(appendKeywords(new StringBuffer(), object), "_UI_Pseudostate_type"), object).toString();

	}

	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(Pseudostate.class)) {
			case UMLPackage.PSEUDOSTATE__KIND:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
				return;
		}
		super.notifyChanged(notification);
	}

	@Override
	protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
	}

	@Override
	public ResourceLocator getResourceLocator() {
		return UMLEditPlugin.INSTANCE;
	}

}
